<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="font-weight: bold">appName</span><span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="appName" placeholder="请输入appName" th:value="${actuator.appName}" class="layui-input">
            <input type="text" name="id" placeholder="请输入id" th:value="${actuator.id}"  style="display: none" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="font-weight: bold">名称</span><span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入名称" th:value="${actuator.title}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required"><span style="font-weight: bold">注册方式</span></label>
        <div class="layui-input-block">
            <input type="radio" name="addressType" value="0" title="自动注册" checked="">
            <input type="radio" name="addressType" value="1" title="手动录入">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"><span style="font-weight: bold">集群地址</span><span style="color: red">*</span></label>
        <div class="layui-input-block">
            <textarea   name="addressList" placeholder="请输入执行器地址列表，多个以逗号分隔" th:value="${actuator.addressList}" class="layui-textarea"></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        form.on('submit(saveBtn)', function (data) {
            var user = JSON.stringify(data.field);
            console.log('--user-user--user-user-user-user-user-user--',user);
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: '/job_actuator/addActuator',
                type: 'post',
                async: false,
                data:user,
                contentType: 'application/json;charset=UTF-8',
                success: function (response) {
                    
                     if (response.code=="200"){
                         layer.alert('保存成功', {
                             time: 1*1000
                             ,success: function(layero, index){
                                 var timeNum = this.time/1000, setText = function(start){
                                     layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
                                 };
                                 setText(!0);
                                 this.timer = setInterval(setText, 1000);
                                 if(timeNum <= 0) clearInterval(this.timer);
                             }
                             ,end: function(){
                                 clearInterval(this.timer);
                                 layer.close(index);
                                 var iframeIndex = parent.layer.getFrameIndex(window.name);
                                 parent.layer.close(iframeIndex);
                                 window.parent.reload();
                             }
                         });
                     }else if (response.code=="500"){
                         layer.msg(response.message, {
                             offset: 'd',
                             anim: 1
                         });
                         layer.close(index);
                     }



                },
                error: function (error) {
                    console.log(1234566);
                    console.log('error',error)
                    layer.alert(error.responseJSON.message)
                    layer.close(index);
                }
            })
            return false;
        });

    });
</script>
</body>
</html>